package com.louis.scheduler.listener;

import org.quartz.*;

import com.louis.scheduler.support.JobDetailAndTrigger;

import javax.mail.MessagingException;


/**
 * @author Lijun jiang
 * @Date: May 12, 2011
 * @Time: 2:11:44 PM
 */

public class RetryListener implements JobListener, TriggerListener {
    public String getName() {
        return "retryListener";
    }

    public void triggerFired(Trigger trigger, JobExecutionContext context) {

    }

    public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
        return true;
    }

    public void triggerMisfired(Trigger trigger) {
    }

    public void triggerComplete(Trigger trigger, JobExecutionContext context, int triggerInstructionCode) {

    }

    public void jobToBeExecuted(JobExecutionContext context) {

    }

    public void jobExecutionVetoed(JobExecutionContext context) {

    }

    public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
        if (context != null) {
            JobDetailAndTrigger jobDetailAndTrigger = (JobDetailAndTrigger) context.getJobInstance();
            try {
                jobDetailAndTrigger.retry(context);
            } catch (SchedulerException e) {
                e.printStackTrace();
            } catch (MessagingException e) {
                e.printStackTrace();
            }
        }
    }
}